import java.util.Scanner;
import java.util.Stack;
public class E1T2 {
    public static void main(String[] args) {
        Stack<String> s = new Stack<>();
        //读取并处理数据
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();scanner.nextLine();
        String str1 = scanner.nextLine();
        String str2 = scanner.nextLine();
        if(!str1.contains(" ")) {
            System.out.println(0);
            return;
        }
        String[] nums1 = str1.split(" ");
        String[] nums2 = str2.split(" ");
        //双指针分别从前向后遍历两个数组
        StringBuilder stringBuilder = new StringBuilder();
        for (int i=0,j=0; i<n && j<n; i++) {
            s.push(nums1[i]);
            stringBuilder.append(nums1[i]+"_in ");//记录
            while(!s.isEmpty()) {
                String top = s.peek();
                if(top.equals(nums2[j])) {
                    s.pop();
                    stringBuilder.append(nums2[j]+"_out ");//记录
                    j++;
                }else {
                    break;//说明已经不符合出栈序列了
                }
            }
        }
        if(s.isEmpty()) {
            System.out.println(1);
            System.out.println(stringBuilder);
        }else {
            System.out.println(0);
        }
    }
}
